package com.ruantu.clothing.service.impl;

import com.ruantu.clothing.dao.ZkSeasonMapper;
import com.ruantu.clothing.entity.ZkSeason;
import com.ruantu.clothing.service.ZkSeasonService;
import com.ruantu.clothing.util.MyException;
import com.ruantu.clothing.util.UUIDUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2018/7/26 0026.
 */
@Service
public class ZkSeasonServiceImpl implements ZkSeasonService {

    @Autowired
    private ZkSeasonMapper zkSeasonMapper;

    @Override
    public List<ZkSeason> findListZhekou(String jgid) {
        return zkSeasonMapper.findListZhekou(jgid);
    }

    @Override
    public int saveZk(ZkSeason zkSeason) {
        if (StringUtils.isNotBlank(zkSeason.getId())) {//修改
            int code = zkSeasonMapper.updateZk(zkSeason);
            if (code <= 0) {
                throw new MyException("保存失败，请检查数据重新尝试");
            }

        } else {//新增
            int count = zkSeasonMapper.findCount(zkSeason);
            if (count > 0) {
                throw new MyException("已存在该折扣，请确认数据重新尝试");
            }
            zkSeason.setId(UUIDUtil.getUUID());
            int code = zkSeasonMapper.insertZk(zkSeason);
            if (code <= 0) {
                throw new MyException("保存失败，请检查数据重新尝试");
            }
        }
        return 1;
    }


}
